package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.dtos.ArticleInfoDto;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章控制层
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/article")
@RequiredArgsConstructor
public class ArticleHomeController {

    //注入service
    private final ApArticleService apArticleService;


    /**
     * 加载首页
     *
     * @return
     */
    @ApiOperation("加载首页")
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        log.info("加载首页...{}",dto);

        //默认查询更多
        //return apArticleService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);

        return apArticleService.load2(dto, ArticleConstants.LOADTYPE_LOAD_MORE,true);
    }



    /**
     * 加载更多----向下滑动
     *
     * @return
     */
    @ApiOperation("加载更多")
    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        log.info("加载更多...{}",dto);

        //默认查询更多
        return apArticleService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }


    /**
     * 加载最新----向下拉
     *
     * @return
     */
    @ApiOperation("加载更新")
    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        log.info("加载更新...{}",dto);

        //默认查询更多
        return apArticleService.load(dto, ArticleConstants.LOADTYPE_LOAD_NEW);
    }


    /**
     * 加载文章行为-数据回显
     *
     * @return
     */
    @ApiOperation("加载文章行为-数据回显")
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto){
        log.info("加载文章行为-数据回显...{}",dto);

        //默认查询更多
        return apArticleService.loadArticleBehavior(dto);
    }

}
